package com.xcity.game.task.detector;

import com.alibaba.fastjson.JSONObject;
import com.xcity.game.employee.config.impl.EmployeeRecruitConfigure;
import com.xcity.game.task.Task;
import com.xcity.game.task.TaskDetector;
import com.xcity.game.task.TaskDetectorLabel;

/**
 * 钻石招聘
 * 1个参数:
 * 1.招聘数量
 * @author shipeng.zhu
 */
@TaskDetectorLabel(TaskDetector.RECRUIT_EMPLOYEE_STONE)
public class RecruitEmployeeStoneTaskDetector implements TaskDetector {

	static final String KEY = String.valueOf(RECRUIT_EMPLOYEE_STONE);
	
	@Override
	public boolean isFinish(Task task) {
		int count = task.getTemplate().getConditions()[0];
		int progress = task.getArchive().getIntValue(KEY);
		return progress >= count;
	}

	@Override
	public void onArchive(Task task, Object... vals) {
		//{23: 招聘次数}
		byte type = (byte) vals[1];
		if(type == EmployeeRecruitConfigure.RECRUIT_TYPE_STONE_ONE){
			JSONObject archive = task.getArchive();
			archive.put(KEY, archive.getIntValue(KEY) + 1);
		}else if(type == EmployeeRecruitConfigure.RECRUIT_TYPE_STONE_TEN){
			JSONObject archive = task.getArchive();
			archive.put(KEY, archive.getIntValue(KEY) + 10);
		}
	}
}
